#ifndef MYSERVER_H
#define MYSERVER_H

#include <QObject>
#include<QTcpServer>
#include<QTcpSocket>
#include<tcpclientsocket.h>
#include<QDebug>

//用结构体给客户端套接字封装一个标识符
struct My_TcpClientSocket
{
    QString socket_name;
    TcpClientSocket* m_tcpClientSocket;
};

class MyServer : public QTcpServer
{
    Q_OBJECT
public:
    explicit MyServer(QObject *parent = nullptr);
    ~MyServer();
    void start_listen(const QString port);//开始监听
    void incomingConnection(qintptr socketDescriptor) override;
    QList<My_TcpClientSocket*> m_tcpClientSocketList;//连接到服务器的客户端列表
    void sendtoClient(QString,QString);//发送消息给客户端
    int* client_count;//连入客户端的数量
public slots:
    //处理服务器收到tcpsocket发过来的消息
    void slotUpdateServer(QString);
    //处理客户端断开连接
    void slotClientDisconnected(qintptr);

signals:
    void send_message(QString);
    void send_socketname(QString);
private:

};

#endif // MYSERVER_H
